// 父组件
<template>
  <div>
    <div>
      <input class="item" v-model="inputVaule" />
      <button @click="handleSubmit">提交</button>
    </div>
    <ul>
      <todo-item
        v-for="(item,index) of list"
        :key="index"
        :content="item"
        :index="index"
        @delete="handDelete"
      ></todo-item>
    </ul>
  </div>
</template>

<script>
import TodoItem from "./components/TodoItem";
export default {
  // 注册子组件组件
  components: {
    // 用todo-item标签去使用TodoItem这个组件
    "todo-item": TodoItem
  },
  data() {
    return {
      inputVaule: "",
      list: []
    };
  },
  methods: {
    handleSubmit() {
      this.list.push(this.inputVaule);
      this.inputVaule = "";
    },
    handDelete(index) {
      this.list.splice(index, 1);
    }
  }
};
</script>

<style>
</style>
